﻿namespace CookieTerm
{
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.ComponentModel;

    class FontBox : Label, INotifyPropertyChanged
    {
        FontDialog dialog = new FontDialog();
        string fontName;
        float fontSize;

        public event PropertyChangedEventHandler PropertyChanged;

        public Tuple<string, float> DisplayFont
        {
            get
            {
                return Tuple.Create(this.fontName, this.fontSize);
            }
            set
            {
                if (value != null)
                {
                    this.fontName = value.Item1;
                    this.fontSize = value.Item2;
                    this.Font = new Font(this.fontName, this.fontSize);
                    
                    Text = Font.Name + " " + Font.Size;
                    Invalidate();
                }
            }
        }

        public XmlColor DisplayBackColor
        {
            get
            {
                return XmlColor.FromRgb(BackColor.ToArgb());
            }
            set
            {
                BackColor = value.ToColor();
            }
        }

        public XmlColor DisplayForeColor
        {
            get
            {
                return XmlColor.FromRgb(ForeColor.ToArgb());
            }
            set
            {
                ForeColor = value.ToColor();
            }
        }

        protected override void OnDoubleClick(EventArgs e)
        {
            this.dialog.Font = Font;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                DisplayFont = Tuple.Create(this.dialog.Font.Name, this.dialog.Font.Size);
                
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("DisplayFont"));
                }
            }
        }
    }
}
    